#ifndef DBUSSERVICE_H
#define DBUSSERVICE_H

#include <QObject>

#include <QtDBus>
#include <QDBusInterface>
#include <QtDeclarative/qdeclarative.h>
#include <QDeclarativeEngine>
#include <QDeclarativeContext>


class DbusService : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QString path WRITE setPath READ path())
    Q_PROPERTY(QString service WRITE setService READ service())
    Q_PROPERTY(bool connected READ isConnected())
    Q_PROPERTY(QString registerName WRITE setSignalHandler  READ signalHandler() )
    Q_PROPERTY(QVariant dbus READ dbus())

public:
    explicit DbusService();
    void setService(const QString & service);
    void setPath(const QString & name);
    void setSignalHandler(const QString & path);

    inline QString path() {return m_path;};
    inline QString service() {return m_service;};
    inline QString signalHandler() {return m_signalHandler;};

    bool isConnected();

    QVariant dbus();

    Q_INVOKABLE void invokeDbusMethod(QString methodName,QList<QVariant> argumentList);
    Q_INVOKABLE void checkServiceExists();
    /*Q_INVOKABLE void invokeQmlMethod(QString methodNam,QList<QVariant> argumentLis);
    Q_INVOKABLE void registerSignal(QString dbusSgl,QString qmlSgl);
    static QDeclarativeEngine * engine;*/

signals :
    void initialized();
    void uninitialized();

private:
    QString m_path;
    QString m_service;
    QString m_signalHandler;
    QDBusInterface* serv;
    bool init;

    void registerServ();
    void afterBeanInit();

private slots :
    void serviceOwnerChanged(QString name,QString oldOwner,QString newOwner);

};

#endif // DBUSSERVICE_H
